import { Component, OnInit } from '@angular/core'
import { TREE_DATA, OrgNode } from '../org-node'
import { NestedTreeControl } from '@angular/cdk/tree'
import { MatTreeNestedDataSource } from '@angular/material'

@Component({
  selector: 'Org-Tree',
  templateUrl: './org-tree.component.html',
  styleUrls: ['./org-tree.component.less']
})
export class OrgTreeComponent implements OnInit {
  treeControl = new NestedTreeControl<OrgNode>(node => node.children)
  dataSource = new MatTreeNestedDataSource<OrgNode>()

  /**
   * loop judgement
   */
  hasChild = (_: number, node: OrgNode) => !!node.children && node.children.length > 0

  constructor() {
    this.dataSource.data = [TREE_DATA]
  }

  ngOnInit(): void { }
}
